# eric7.Utilities.ClassBrowsers.pyclbr

Parse a Python file and retrieve classes, functions/methods and attributes.

Parse enough of a Python file to recognize class and method definitions and to find out the superclasses of a class as well as its attributes.

### Global Attributes

SUPPORTED_TYPES
TABWIDTH
_commentsub
_getnext

### Classes

Attribute | Class to represent a class attribute.
Class | Class to represent a Python class.
Function | Class to represent a Python function.
ImportedModule | Class to represent an imported module.
Imports | Class to represent the list of imported modules.
Metadata | Class to represent the list of metadata sections.
MetadataEntry | Class defining the data structure for a metadata entry.
Publics | Class to represent the list of public identifiers.
VisibilityMixin | Mixin class implementing the notion of visibility.

### Functions

_indent | Module function to return the indentation depth.
calculateEndline | Function to calculate the end line of a class or method/function.
readmodule_ex | Read a module file and return a dictionary of classes.
scan | Public method to scan the given source text.

## Attribute

Class to represent a class attribute.

### Derived from

ClbrBaseClasses.Attribute, VisibilityMixin

### Class Attributes

None

### Class Methods

None

### Methods

Attribute | Constructor

### Static Methods

None

#### Attribute (Constructor)

Attribute(module, name, file, lineno, col_offset=0)

Constructor

module (str)
  name of the module containing this class
name (str)
  name of this class
file (str)
  file name containing this attribute
lineno (int)
  line number of the attribute definition
col_offset (int (optional))
  column number of the attribute definition (defaults to 0)

Up

## Class

Class to represent a Python class.

### Derived from

ClbrBaseClasses.Class, VisibilityMixin

### Class Attributes

None

### Class Methods

None

### Methods

Class | Constructor

### Static Methods

None

#### Class (Constructor)

Class(module, name, superClasses, file, lineno, col_offset=0)

Constructor

module (str)
  name of the module containing this class
name (str)
  name of this class
superClasses (list of str)
  list of class names this class is inherited from
file (str)
  file name containing this class
lineno (int)
  line number of the class definition
col_offset (int (optional))
  column number of the class definition (defaults to 0)

Up

## Function

Class to represent a Python function.

### Derived from

ClbrBaseClasses.Function, VisibilityMixin

### Class Attributes

None

### Class Methods

None

### Methods

Function | Constructor

### Static Methods

None

#### Function (Constructor)

Function(module, name, file, lineno, col_offset=0, signature="", separator=", ", modifierType=ClbrBaseClasses.Function.General, annotation="", )

Constructor

module (str)
  name of the module containing this function
name (str)
  name of this function
file (str)
  file name containing this function
lineno (int)
  line number of the function definition
col_offset (int (optional))
  column number of the function definition (defaults to 0)
signature (str)
  parameter list of the function
separator (str)
  string separating the parameters
modifierType (int)
  type of the function
annotation (str)
  return annotation

Up

## ImportedModule

Class to represent an imported module.

### Derived from

None

### Class Attributes

None

### Class Methods

None

### Methods

ImportedModule | Constructor
addImport | Public method to add a list of imported names.

### Static Methods

None

#### ImportedModule (Constructor)

ImportedModule(module, file, importedModule)

Constructor

module (str)
  name of the module containing the import
file (str)
  file name containing the import
importedModule (str)
  name of the imported module

#### ImportedModule.addImport

addImport(lineno, importedNames)

Public method to add a list of imported names.

lineno (int)
  line number of the import
importedNames (list of str)
  list of imported names

Up

## Imports

Class to represent the list of imported modules.

### Derived from

None

### Class Attributes

None

### Class Methods

None

### Methods

Imports | Constructor
addImport | Public method to add a list of imported names.
getImport | Public method to get an imported module item.
getImports | Public method to get all imported module names.

### Static Methods

None

#### Imports (Constructor)

Imports(module, file)

Constructor

module (str)
  name of the module containing the import
file (str)
  file name containing the import

#### Imports.addImport

addImport(moduleName, names, lineno)

Public method to add a list of imported names.

moduleName (str)
  name of the imported module
names (list of str)
  list of names
lineno (int)
  line number of the import

#### Imports.getImport

getImport(moduleName)

Public method to get an imported module item.

moduleName (str)
  name of the imported module

Return:
  imported module item

Return Type:
  ImportedModule

#### Imports.getImports

getImports()

Public method to get all imported module names.

Return:
  dictionary of imported module names with name as key and list of line numbers of imports as value

Return Type:
  dict

Up

## Metadata

Class to represent the list of metadata sections.

### Derived from

None

### Class Attributes

None

### Class Methods

None

### Methods

Metadata | Constructor
addMetadata | Public method to add the type name of a metadata section.
getMetadata | Public method to get a metadata item.
getMetadataEntries | Public method to get all imported module names.

### Static Methods

None

#### Metadata (Constructor)

Metadata(file)

Constructor

file (str)
  file name containing the metadata

#### Metadata.addMetadata

addMetadata(metadataType, metadataContent, lineno)

Public method to add the type name of a metadata section.

metadataType (str)
  type name of the metadata section
metadataContent (str)
  content of the metadata section
lineno (int)
  line number of the import

#### Metadata.getMetadata

getMetadata(metadataType)

Public method to get a metadata item.

metadataType (str)
  type name of the metadata section

Return:
  metadata item

Return Type:
  MetadataEntry

#### Metadata.getMetadataEntries

getMetadataEntries()

Public method to get all imported module names.

Return:
  dictionary of imported module names with name as key and list of line numbers of imports as value

Return Type:
  dict

Up

## MetadataEntry

Class defining the data structure for a metadata entry.

### Derived from

None

### Class Attributes

content
file
lineno
typ

### Class Methods

None

### Methods

None

### Static Methods

None

Up

## Publics

Class to represent the list of public identifiers.

### Derived from

None

### Class Attributes

file
identifiers
lineno
module
name

### Class Methods

None

### Methods

None

### Static Methods

None

Up

## VisibilityMixin

Mixin class implementing the notion of visibility.

### Derived from

ClbrBaseClasses.ClbrVisibilityMixinBase

### Class Attributes

None

### Class Methods

None

### Methods

VisibilityMixin | Constructor

### Static Methods

None

#### VisibilityMixin (Constructor)

VisibilityMixin()

Constructor

Up

## _indent

_indent(ws)

Module function to return the indentation depth.

ws (str)
  the whitespace to be checked

Return:
  length of the whitespace string

Return Type:
  int

Up

## calculateEndline

calculateEndline(lineno, lines, indent)

Function to calculate the end line of a class or method/function.

lineno (int)
  line number to start at (one based)
lines (list of str)
  list of source lines
indent (int)
  indent length the class/method/function definition

Return:
  end line of the class/method/function (one based)

Return Type:
  int

Up

## readmodule_ex

readmodule_ex(module, searchPath=None, isTypeFile=False)

Read a module file and return a dictionary of classes.

Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module.

module (str)
  name of the module file
searchPath (list of str)
  path the module should be searched in
isTypeFile (bool)
  flag indicating a file of this type

Return:
  the resulting dictionary

Return Type:
  dict

Up

## scan

scan(src, file, module)

Public method to scan the given source text.

src (str)
  source text to be scanned
file (str)
  file name associated with the source text
module (str)
  module name associated with the source text

Return:
  dictionary containing the extracted data

Return Type:
  dict

Up